//
//  PPAlbumPictureView.m
//  pickpic
//
//  Created by Jinxiao on 9/29/16.
//  Copyright © 2016 MicroDream. All rights reserved.
//

#import "PPAlbumPictureDescriptionView.h"

@interface PPAlbumPictureDescriptionView ()

@property (nonatomic,strong) UITextField *textField;
@end

@implementation PPAlbumPictureDescriptionView

- (instancetype)init {
    self = [super init];
    self.backgroundColor = [UIColor colorWithRGBHex:0x00 alpha:0.8];
    
//    self.backgroundColor = BLUE;
    
//    _textField.leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"desc_icon"]];
//    _textField.placeholder = @"添加描述";
//    [self addSubview:_textField];
    
    _label = [[UILabel alloc] init];
    _label.numberOfLines = 0;
    _label.backgroundColor = CLEAR;
    
    _label.textAlignment = NSTextAlignmentLeft;
    _label.lineBreakMode = NSLineBreakByWordWrapping;
//    _label.font = [UIFont systemFontOfSize:13];
    _label.font = PPFONTSIZE(kDescFontSize);
    _label.textColor = [UIColor whiteColor];
    [_label sizeToFit];
    [self addSubview:_label];

    [_label mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.equalTo(self).insets(UIEdgeInsetsMake(6, 12, 15, 12));
         make.edges.equalTo(self).insets(UIEdgeInsetsMake(kAlbumDescTopBottomMargin, kAlbumDescLeftRightMargin, kAlbumDescTopBottomMargin-2*kLabelMargin, kAlbumDescLeftRightMargin));
        
    }];

    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];

//    _label.frame = CGRectMake(12, 6, self.width - 26, self.height - 15);
    
}

- (void)setDesc:(NSString *)desc {
    _desc = desc;

    if(_desc.length == 0) {
        self.hidden = YES;
    } else {
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        paragraph.alignment = NSTextAlignmentLeft;
        paragraph.lineBreakMode = NSLineBreakByWordWrapping;
        paragraph.lineSpacing = kAlbumDescLinespace/2;
        _label.attributedText = [[NSAttributedString alloc] initWithString:_desc attributes:@{NSFontAttributeName: PPFONTSIZE(kDescFontSize), NSParagraphStyleAttributeName: paragraph}];

        self.hidden = NO;
    }

    
//   CGFloat h = [_label rectHeightWithText:_desc width:(SCREEN_WIDTH-kAlbumDescLeftRightMargin*2) font:PPFONTSIZE(kDescFontSize)];
//    
//    if (h < 18) {
//
//        [_label mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.offset(kAlbumDescTopBottomMargin);
//            make.height.mas_equalTo(h-kLabelMargin/2);
//            
//        }];
//    }
//    

    

    
    [self setNeedsLayout];
}
@end
